﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@section header{
    <link href="@Url.Content("~/lib/summernote/0.8.15/summernote.min.css")" rel="stylesheet" type="text/css">
    <script src='@Url.Content("~/lib/summernote/0.8.15/summernote.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/lib/summernote/0.8.15/lang/summernote-zh-CN.min.js")' type="text/javascript"></script>
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/imageupload/1.0/css/imgup.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/imageupload/1.0/js/imgup.min.js"))
}
<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <div class="form-group">
            <label class="col-sm-2 control-label ">商铺编号<font class="red"> *</font></label>
            <div class="col-sm-10">
                <input id="shop_code" col="shop_code" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">商铺名称<font class="red"> *</font></label>
            <div class="col-sm-10">
                <input id="shop_name" col="shop_name" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">联系人<font class="red"> *</font></label>
            <div class="col-sm-10">
                <input id="link_man" col="link_man" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">联系电话<font class="red"> *</font></label>
            <div class="col-sm-10">
                <input id="phone_number" col="phone_number" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">银行名称</label>
            <div class="col-sm-10">
                <input id="bank_name" col="bank_name" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">银行账号</label>
            <div class="col-sm-10">
                <input id="bank_account" col="bank_account" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">区域<font class="red"> *</font></label>
            <div class="col-sm-10">
                <div id="_Area" col="_Area"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">商家地址<font class="red"> *</font></label>
            <div class="col-sm-10">
                <input id="address" col="address" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">
                <span>商铺封面</span><font class="red"> *</font><br />
                <span>(宽高比 1.5：1)</span>
            </label>
            <div class="col-sm-10">
                <div id="shop_image_url" class="img-box">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">是否推荐<font class="red"> *</font></label>
            <div class="col-sm-4" id="pick_status" col="pick_status"></div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">经度</label>
            <div class="col-sm-10">
                <input id="longitude" col="longitude" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">纬度</label>
            <div class="col-sm-10">
                <input id="latitude" col="latitude" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">工作状态<font class="red"> *</font></label>
            <div class="col-sm-4" id="status" col="status"></div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">品牌<font class="red"> *</font></label>
            <div class="col-sm-4" id="brandids" col="brandids"></div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {
        $('#_Area').ysComboBoxTree({ url: '@Url.Content("~/SystemManage/Area/GetZtreeAreaListJson")', async: false });

        $("#pick_status").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(PickStatusEnum).EnumToDictionaryString())) });

        $("#status").ysRadioBox({ data: ys.getJson(@Html.Raw(typeof(ShopWorkStatusEnum).EnumToDictionaryString())) });

        $("#shop_image_url").imageUpload({ uploadImage: 'uploadThumbImage', limit: 1, context: ctx });

         $("#brandids").ysComboBox({
            url: '@Url.Content("~/QixingManage/StoreBrand/GetListJson")',
            key: "Id",
            value: "brand_name",
            class: "form-control",
            multiple: true
        });

        getForm();

        $.validator.addMethod("customPhone", function (value, element) {
            return this.optional(element) || /^(?:\+?86)?(?:13\d|15\d|16\d|17\d|18\d|19\d)\d{8}$/.test(value);
        }, "请输入有效的手机号码");

        $('#form').validate({
            rules: {
                shop_code: { required: true },
                shop_name: { required: true },
                shop_type_select: { required: true },
                link_man: { required: true },
                phone_number: {
                    required: true,
                    customPhone: true
                },
                brandids_select: { required: true },
                address: { required: true },
                area: { required: true },
                longitude: { isLongreg: true },
                latitude: { isLatreg: true }
            }
        });

    });

    function getForm() {
        if (id > 0) {
            ys.ajax({
                url: '@Url.Content("~/QixingManage/Store/GetFormJson")' + '?id=' + id,
                type: 'get',
                success: function (obj) {
                    if (obj.Tag == 1) {
                        $("#shop_image_url").imageUpload("setImageUrl", obj.Data.shop_image_url);
                        obj.Data._Area=obj.Data.selected_area
                        $('#form').setWebControls(obj.Data);
                    }
                }
            });
        }
        else {
            var defaultData = {};
            defaultData.status = "@ShopWorkStatusEnum.营业中.ParseToInt()";
            defaultData.pick_status = "@PickStatusEnum.Yes.ParseToInt()";
            $('#form').setWebControls(defaultData);
        }
    }

    function saveForm(index) {
        if ($('#form').validate().form()) {
            var postData = $('#form').getWebControls({ Id: id });
            postData.selected_area= ys.getLastValue(postData._Area);
            postData.shop_image_url = $("#shop_image_url").imageUpload("getImageUrl");
            if (ys.isNullOrEmpty(postData.shop_image_url))
            {
                 return ys.msgError("请上传商铺封面!");
            }
            ys.ajax({
                url: '@Url.Content("~/QixingManage/Store/SaveFormJson")',
                type: 'post',
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }

    function uploadThumbImage(file, callback) {
        var formdata = new FormData();
        formdata.append("fileList", file);
        ys.ajaxUploadFile({
            url: '@GlobalContext.SystemConfig.ApiSite' + '/File/UploadFile?fileModule=@UploadFileType.Qixing.ParseToInt()',
            data: formdata,
            success: function (obj) {
                if (obj.Tag == 1) {
                    if (callback) {
                        callback('@GlobalContext.SystemConfig.ApiSite' + obj.Data);
                    }
                }
                else {
                    ys.msgError(obj.Message);
                }
            }
        })
    }
</script>

